#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: split a pvalue input file into a set of pvalue input files
#Usage: splitgenerecords.pl <inputfile>

my $numargs =$#ARGV + 1;
if ($numargs != 1) {
	print STDERR "Usage: splitgenerecords.pl <inputfile>\n";
}
my $if = $ARGV[0];
chomp $if;
my $numrecords = `cat $if | grep -P '^\$' | wc -l`;
chomp $numrecords;
$numrecords++;
print "NUMRECORDS: $numrecords\n";
open(IF, "$if");
$numrecords--;
while (my $firstline = <IF>) {
	open(OF, ">$if.$numrecords");
	print OF $firstline;
	my $line;
	while (($line = <IF>) && ($line !~ /^$/)) {
		print OF $line;
	}
	print "\n";
	$numrecords--;
}
